<?php
namespace App\Repository\User;

use App\Facade\Event;
use App\Event\User\MoneyFullEvent;
use App\Event\User\MoneyFullAllEvent;

Trait MoneyFull
{
    // 使用
    public function moneyFullMake($money, $content, $type = '')
    {
        if($this->moneyFullHas($money))
        {
            return $this->moneyFullAdd(-1 * $money, $content, $type);
        }
    }
    
    // 判断
    public function moneyFullHas($money)
    {
        if($money > 0)
        {
            return $this->model->money_full >= $money;
        }
    }
    
    // 增加
    public function moneyFullAdd($money, $content, $type = '')
    {
        $res = $this->model->increment('money_full', $money);
        
        Event::dispatch(new MoneyFullEvent($this, $money, $content, $type));
            
        return $res;
    }
    
    // 累计
    public function moneyFullAll($money)
    {
        $this->model->increment('money_full_all', $money);
        
        Event::dispatch(new MoneyFullAllEvent($this, $money));
    }
}